﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Casemeet.Lines;
using VK.Comm;
using VK.Casemeet.Employees;

namespace VK.Casemeet.Web.Admin.Lines
{
    public partial class FeatureEdit : System.Web.UI.Page
    {
        public int featureID = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            (this.Master as Site).SiteMapPathControl.MapPathList = new List<MapPath>(){
                new MapPath{ Text="桌面",Url="/Admin/Home.aspx"},
                new MapPath{ Text="特色线路列表",Url="/Admin/Lines/FeatureList.aspx"},
                new MapPath{ Text="编辑",Url="#"}
            };

            featureID = Util.GetQueryInt("FeatureID");

            if (!IsPostBack)
            {
                //GoodsHelper.BindDeprDDL(ddlDepr, OptionType.Select);

                LoadData();
            }
        }

        internal void LoadData()
        {
            if (featureID != 0)
            {
                FeatureEntity feature = FeatureBLL.GetFeature(featureID);
                txtLineID.Text = feature.LineID.ToString();
                txtSort.Text = feature.Sort.ToString();
                txtCreated.Text = Util.FormatDateTime(feature.Created, DateTimeStyle.ShortDate2);
            }
        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            FeatureEntity feature = LoadEntity();
            feature.FeatureID = featureID;

            if (FeatureBLL.UpdateFeature(feature) > 0)
            {
                Message.Msg(this.Page, CS.MsgEditSuccess, MessageType.Success);
            }
            else
            {
                Message.Msg(this.Page, CS.MsgEditFailure, MessageType.Failure);
            }
            LoadData();
        }

        protected FeatureEntity LoadEntity()
        {
            FeatureEntity feature = new FeatureEntity();
            feature.LineID = int.Parse(txtLineID.Text);
            feature.Sort = int.Parse(txtSort.Text);
            feature.ProvinceID = EmployeeService.GetSessionEmployee().ProvinceID;
            feature.CityID = EmployeeService.GetSessionEmployee().CityID;
            feature.Created = Util.ConverDateTime(txtCreated.Text);

            return feature;
        }
    }
}